package com.xuecheng.controller;

import com.xuecheng.dto.MyCourseTableParamsDTO;
import com.xuecheng.exception.XueChengPlusException;
import com.xuecheng.model.PageResult;
import com.xuecheng.service.MyCourseTablesService;
import com.xuecheng.util.SecurityUtil;
import com.xuecheng.vo.MyCourseTableItemVO;
import com.xuecheng.vo.XcChooseCourseVO;
import com.xuecheng.vo.XcCourseTablesVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 我的课程表接口
 */
@Api(value = "我的课程表接口", tags = "我的课程表接口")
@Slf4j
@RestController
public class MyCourseTablesController {
	
	@Resource
	private MyCourseTablesService myCourseTablesService;
	
	@ApiOperation("添加选课")
	@PostMapping("/choosecourse/{courseId}")
	public XcChooseCourseVO addChooseCourse(@PathVariable("courseId") Long courseId) {
		//登录用户
		SecurityUtil.XcUser user = SecurityUtil.getUser();
		if (user == null) {
			XueChengPlusException.cast("请登录后继续选课");
		}
		return myCourseTablesService.addChooseCourse(user.getId(), courseId);
		
	}
	
	@ApiOperation("查询学习资格")
	@PostMapping("/choosecourse/learnstatus/{courseId}")
	public XcCourseTablesVO getLearnstatus(@PathVariable("courseId") Long courseId) {
		//登录用户
		SecurityUtil.XcUser user = SecurityUtil.getUser();
		if (user == null) {
			XueChengPlusException.cast("请登录后继续选课");
		}
		return myCourseTablesService.getLeanringStatus(user.getId(), courseId);
		
	}
	
	@ApiOperation("我的课程表")
	@GetMapping("/mycoursetable")
	public PageResult<MyCourseTableItemVO> mycoursetable(MyCourseTableParamsDTO myCourseTableParamsDTO) {
		//登录用户
		SecurityUtil.XcUser user = SecurityUtil.getUser();
		if (user == null) {
			XueChengPlusException.cast("请登录后继续选课");
		}
		myCourseTableParamsDTO.setUserId(user.getId());
		return myCourseTablesService.mycourestabls(myCourseTableParamsDTO);
		
	}
	
	
}
